//
//  MerchantInfoViewController.m
//  YTwallet
//
//  Created by ZhangLin on 2019/3/4.
//  Copyright © 2019年 hadrlog. All rights reserved.
//

#import "MerchantInfoViewController.h"
#import "MerchantInfoTableViewCell.h"
#import <Masonry.h>
#import "MerchantAddresTableViewCell.h"
@interface MerchantInfoViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *tableView;
@property(nonatomic,strong)NSMutableArray *tipsArray0;
@property(nonatomic,strong)NSMutableArray *tipsValueArray0;
@property(nonatomic,strong)NSMutableArray *tipsArray1;
@property(nonatomic,strong)NSMutableArray *tipsValueArray1;

@property(nonatomic,strong)UIButton *logoutBtn;

@end

@implementation MerchantInfoViewController

-(NSMutableArray *)tipsArray0
{
    if (_tipsArray0 == nil) {
        _tipsArray0 = [NSMutableArray array];
    }
    return _tipsArray0;
}
-(NSMutableArray *)tipsArray1
{
    if (_tipsArray1 == nil) {
        _tipsArray1 = [NSMutableArray array];
    }
    return _tipsArray1;
}
-(NSMutableArray *)tipsValueArray0
{
    if (_tipsValueArray0 == nil) {
        _tipsValueArray0 = [NSMutableArray array];
    }
    return _tipsValueArray0;
}
-(NSMutableArray *)tipsValueArray1
{
    if (_tipsValueArray1 == nil) {
        _tipsValueArray1 = [NSMutableArray array];
    }
    return _tipsValueArray1;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商户资料";
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    //创建tableView
    [self createTableView];
    //退出
    [self logout];
    
}
-(void)logout
{
    self.logoutBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.logoutBtn setTitle:@"退出登录" forState:(UIControlStateNormal)];
    self.logoutBtn.backgroundColor = [UIColor colorWithRed:91 / 255.0 green:113 / 255.0 blue:255 / 255.0 alpha:1];
    self.logoutBtn.layer.cornerRadius = 22;
    [self.view addSubview:self.logoutBtn];
    [self.logoutBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-25);
        make.bottom.equalTo(self.view).offset(-50);
        make.height.mas_equalTo(44);
    }];
}
-(void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:(CGRectMake(0, 10, self.view.frame.size.width, self.view.frame.size.height - 10)) style:(UITableViewStyleGrouped)];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.tableView registerClass:[MerchantInfoTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.tipsArray0 = @[@"商户编号",@"商户等级",@"实名认证"].mutableCopy;
    self.tipsArray1 = @[@"商户名称",@"商户手机号",@"身份证号",@"商户地址"].mutableCopy;
    self.tipsValueArray0 = @[@"123123",@"至尊会员",@"已认证"].mutableCopy;
    self.tipsValueArray1 = @[@"啦啦啦",@"136****3232",@"310109****2672",@"上海市闵行区c合川路虹桥国际大楼5楼508"].mutableCopy;
    [self.tableView registerClass:[MerchantInfoTableViewCell class] forCellReuseIdentifier:@"InfoCell"];
    [self.tableView registerClass:[MerchantAddresTableViewCell class] forCellReuseIdentifier:@"addressCell"];
    [self.view addSubview:self.tableView];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case 0:
            return 3;
            break;
        case 1:
            return 4;
            break;
        default:
            break;
    }
    
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MerchantInfoTableViewCell *cell;
    if (indexPath.section == 1 && indexPath.row == 3) {
        MerchantInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"addressCell"];
        
        cell.tipsLab.text = @"商户地址";
        cell.tipsValueLab.text = @"上海市闵行区c合川路虹桥国际大楼5楼508";
        return cell;
        
        
    }else
    {
       cell  = [tableView dequeueReusableCellWithIdentifier:@"InfoCell" forIndexPath:indexPath];
    }
    
    
    
    if (indexPath.section == 0) {
        
        if (indexPath.row == 1 || indexPath.row == 2) {
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }else
        {
            [cell.tipsValueLab mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-15);
                make.centerY.equalTo(cell);
            }];
        }
        cell.tipsLab.text = self.tipsArray0[indexPath.row];
        cell.tipsValueLab.text = self.tipsValueArray0[indexPath.row];
    }else if (indexPath.section == 1)
    {

        cell.tipsLab.text = self.tipsArray1[indexPath.row];
        cell.tipsValueLab.text = self.tipsValueArray1[indexPath.row];
        [cell.tipsValueLab mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-15);
         }];
    }
    
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01f;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1 && indexPath.row == 3) {
        return 80;
    }
    
    return 44;
}



@end
